package cn.fl.project.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.index.constant.PrjPlcyIndexConstant;
import cn.fl.project.condition.CalQuatPrpsQC;
import cn.fl.project.condition.PrjQuatPrpsCfgDQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsCfgMQueryCondition;
import cn.fl.project.constant.CalQuatPrpsConstant;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjQuatPrpsConstant;
import cn.fl.project.constant.PrjQuatPrpsFeeConstant;
import cn.fl.project.service.*;
import cn.fl.project.vo.*;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.utils.FundRasInsNmChangeUtil;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import net.sf.json.JSONArray;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description: 报价器-方案 控制层
 */
@Controller
@RequestMapping("/project/calquatprps")
public class CalQuatPrpsController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(CalQuatPrpsController.class);

	/**
	 * CalQuatPrps 服务层BEAN
	 */
	@Autowired
	private ICalQuatPrpsService calQuatPrpsService;
    @Autowired
    private IPrjQuatPrpsCfgMService prjQuatPrpsCfgMService;
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;//数据字典

    @Autowired
    private IPrjQuatPrpsCfgDService prjQuatPrpsCfgDService;
    @Autowired
    private IPrjBscInfoService prjBscInfoService;//项目基础信息
    @Autowired
    private IPrjQuatPrpsService prjQuatPrpsService;
    @Autowired
    private IFriBaseInfoService friBaseInfoService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		ModelAndView view = new ModelAndView("project/calQuatPrps/calQuatPrpsList");
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

    /**
     * 到方案配置列表页面
     */
    @RequestMapping(value = "/toChooseQuatPrpsListPage.do", method = { RequestMethod.GET})
    public ModelAndView toChooseQuatPrpsListPage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toListPage", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

        ModelAndView view = new ModelAndView("project/calQuatPrps/calQuatPrpsCgfMList");

        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toListPage", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return view;
    }
	
	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        String prpsCfgId = request.getParameter("prpsCfgId");//方案配置ID
        String id = request.getParameter("id");
        String detailFlag = request.getParameter("detailFlag");
        ModelAndView view = new ModelAndView("project/calQuatPrps/calQuatPrpsAdd");
        //产品分类IRR
        List<SysDictionaryDTO> prdTypIrrList = this.getSysDictionaryList(DictionaryConstant.CODE_PRD_TYP_IRR_CD);
//        List<SysDictionaryDTO> prdTypIrrList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd() , CurrentThreadContext.getCurrentOrgCd(),DictionaryConstant.CODE_PRD_TYP_IRR_CD);
        //厂商贴息方案分类
        List<KeyValueVO> mfrPrpsTypCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_MFR_PRPS_TYP_CD,CurrentThreadContext.getCurrentSysCd() , CurrentThreadContext.getCurrentOrgCd());


//          中文的银行
//        getInsCodeList(view);

        //模式
        getInsQuatTypList(view);

        //根据选中的模式找出相应的机构
        differentInsCodeAndInsQuatTyp(view);

        PrjQuatPrpsCfgMVO 	quatPrps = null;
        CalQuatPrpsVO   calQuatPrps = null;
        List<PrjQuatPrpsCfgDVO> list = null;
        if(StringUtils.isNotEmpty(prpsCfgId)){
            quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
            Pager page = new Pager();

            PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
            page.setEveryPage(Integer.MAX_VALUE);//最大数据量
            qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
            page.setCondition(qc);
            Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
            list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
        }

        //根据id查询修改数据
        if(StringUtils.isNotBlank(id)){
            //查询已经保存的报价方案
             calQuatPrps = this.calQuatPrpsService.selectCalQuatProsAndDetailById(Long.valueOf(id));
            ListPageVO<CalPaySchVO> payListPage = new ListPageVO<CalPaySchVO>(calQuatPrps.getPayList(),calQuatPrps.getPayList().size());
            calQuatPrps.setPayListPage(payListPage);
            ListPageVO<CalQuatPrpsFeeVO> detailListPage = new ListPageVO<CalQuatPrpsFeeVO>(calQuatPrps.getFeeList(),calQuatPrps.getFeeList().size());

            calQuatPrps.setFeeListPage(detailListPage);
            view.addObject("detailListPage", JSON.toJSONString(detailListPage));
            view.addObject("payListPage", JSON.toJSONString(payListPage));
            view.addObject("prjQuatPrps", JSON.toJSONString(calQuatPrps));
        }
        view.addObject("id", id);
        //租赁期数单位
        List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
        view.addObject("lsPdUntCdList", lsPdUntCdList);
        //支付方式
        List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();
        view.addObject("payWayCdList", payWayCdList);
        //保证金处理方式
        List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
        view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
        //租赁期满处理方式
        List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
        view.addObject("expHdlWayCdList", expHdlWayCdList);
        //费用类型
        JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
        view.addObject("feeTypCdListJSON", feeTypCdListJSON);
        //费用计算基数
        List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
        view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
        List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
        view.addObject("yesNoCdList",yesNoCdList);
        view.addObject("yesOrNoCdListJSON",JSON.toJSONString(yesNoCdList) );
        //费用计入方式
        List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
        //计算方式
        List<KeyValueVO> lsCalWayCdList = this.prjBscInfoService.searchLsCalWayCdList();
        //商业险金额
        List<KeyValueVO> businessInsCdList = this.prjBscInfoService.searchBusinessInsCdList();
        view.addObject("businessInsCdList",businessInsCdList);
        //租赁年利率计算方式
        List<KeyValueVO> intRateWayCdList = this.prjBscInfoService.searchIntRateWayCdList();
        Map<String,String> scaleNumMap  =  this.prjQuatPrpsService.getDecimalDigitsByBuOrgCode();
        view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
        view.addObject("quatPrps", quatPrps);//配置方案信息
        view.addObject("quatPrpsJson", quatPrps==null?"": JSON.toJSONString(quatPrps));//配置方案信息
        view.addObject("PrjQuatPrpsCfgDetailList", list);//配置明细信息
        view.addObject("lsPdUntCdList", lsPdUntCdList);//租赁期数单位
        view.addObject("payWayCdList", payWayCdList);//支付方式
        view.addObject("lsCalWayCdList", lsCalWayCdList);//计算方式
        view.addObject("calBaseCdList", calBaseCdList);//费用计算基数
        view.addObject("cntWayCdList", cntWayCdList);///费用计入方式
        view.addObject("intRateWayCdList", intRateWayCdList);//租赁年利率计算方式
        view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);//客户保证金处理方式
        view.addObject("expHdlWayCdList", expHdlWayCdList);//租赁期满处理方式
        view.addObject("prpsCfgId", prpsCfgId);
        view.addObject("calQuatPrps", calQuatPrps);//修改时报价器信息
        view.addObject("scaleNumMap", scaleNumMap.isEmpty()==true?"":JSON.toJSONString(scaleNumMap));
        view.addObject("detailFlag",detailFlag);

        view.addObject("prdTypIrrList",prdTypIrrList);
        view.addObject("mfrPrpsTypCdList",mfrPrpsTypCdList);

         //事业部
        view.addObject("buOrgCd", CurrentThreadContext.getCurrentBuOrgCd());

		Long startTm = System.currentTimeMillis();
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载新增.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载修改页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/calQuatPrps/calQuatPrpsModify");
		view.addObject("id", id);
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toAddPage", "加载修改.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/calQuatPrps/calQuatPrpsDetail");
		view.addObject("id", id);
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/quatPrpsCfgMInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object quatPrpsCfgMInitList(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjQuatPrpsCfgMQueryCondition qc = new PrjQuatPrpsCfgMQueryCondition();
        qc.setExpStDt(new Date());
        qc.setIsValid(BaseConstant.IS_YESNO_YES);
        qc.setPrpsPrdTypCd(CalQuatPrpsConstant.CODE_PRPS_PRD_TYP_CD_4);
        page.setCondition(qc);
        Pager pager = this.prjQuatPrpsCfgMService.searchListPage(page);
        List<PrjQuatPrpsCfgMVO> list = (List<PrjQuatPrpsCfgMVO>) pager.getResultList();
        ListPageVO<PrjQuatPrpsCfgMVO> listPage = new ListPageVO<PrjQuatPrpsCfgMVO>(list, pager.getTotalCount());
        BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }


	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		CalQuatPrpsQC qc = new CalQuatPrpsQC();
        qc.setUsrId(CurrentThreadContext.getCurrentUserId());
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		page.setCondition(qc);
		Pager pager = this.calQuatPrpsService.searchListPage(page);
		List<CalQuatPrpsVO> list = (List<CalQuatPrpsVO>) pager.getResultList();
		ListPageVO<CalQuatPrpsVO> listPage = new ListPageVO<CalQuatPrpsVO>(list, pager.getTotalCount());
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

    /**
     * 新增
     */
    @RequestMapping(value = "/addQuatPrps.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object addQuatPrps(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String quatId = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        CalQuatPrpsVO prjQuatPrps = null;
        Long id  =	 null;
        try {
            prjQuatPrps = getRequestParams(request);
            if(StringUtils.isNotBlank(quatId)){
                prjQuatPrps.setId(Long.valueOf(quatId));
            }
            prjQuatPrps.setMdfTm(new Date());
            prjQuatPrps.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            prjQuatPrps.setCrtTm(new Date());
            prjQuatPrps.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            prjQuatPrps.setSysCd(CurrentThreadContext.getCurrentSysCd());
            prjQuatPrps.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            prjQuatPrps.setCstMgrId(CurrentThreadContext.getCurrentUserId());
            prjQuatPrps.setCstMgrOrgCd(CurrentThreadContext.getCurrentOrgCd());
            prjQuatPrps.setCstMgrNm(CurrentThreadContext.getCurrentUserName());
            prjQuatPrps.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());

            //客户经理id、组织机构、事业部
            id = this.calQuatPrpsService.modifyGenCalQuatPrps(prjQuatPrps);
            result.setData(id);
            BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(prjQuatPrps), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(prjQuatPrps) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(prjQuatPrps) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        return result;
    }

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		CalQuatPrpsVO entity = null;
		try {
			entity = new CalQuatPrpsVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.calQuatPrpsService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "remove", "移除对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}
		try {
			this.calQuatPrpsService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "remove", "移除对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "remove", "移除对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "remove", "移除对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			CalQuatPrpsVO vo = this.calQuatPrpsService.selectCalQuatProsAndDetailById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}


    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
    @ResponseBody
    public DataResultVO removeByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String ids = request.getParameter("ids");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if(StringUtils.isEmpty(ids)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            return result;
        }
        List<Long> idList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idList.add(Long.valueOf(object.toString()));
        }
        try {
            this.calQuatPrpsService.removeCalQuatPrpsAndDetailByIds(idList);
            BaseLogUtils.info(logger, "removeById", "删除数据.[id="+ids+"]", CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+ids+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+ids+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }
    /**
     * 获取报价器费用列表
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getCalQuatFeeById.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object getCalQuatFeeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String prjId = request.getParameter("prjId");
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.error(logger, "getCalQuatFeeById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        CalQuatPrpsVO prjQuatPrps = this.calQuatPrpsService.selectCalQuatProsAndDetailById(Long.valueOf(id));
        ListPageVO<CalQuatPrpsFeeVO> detailListPage = new ListPageVO<CalQuatPrpsFeeVO>(prjQuatPrps.getFeeList(),prjQuatPrps.getFeeList().size());
        prjQuatPrps.setFeeListPage(detailListPage);
        BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(detailListPage), CurrentThreadContext.getCurrentUserName());
        return detailListPage;
    }

    /**
     * 获取报价器费用列表
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getPrjQuatPayById.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object getPrjQuatPayById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String prjId = request.getParameter("prjId");
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.error(logger, "getPrjQuatPayById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        CalQuatPrpsVO prjQuatPrps = this.calQuatPrpsService.selectCalQuatProsAndDetailById(Long.valueOf(id));
        ListPageVO<CalPaySchVO> detailListPage = new ListPageVO<CalPaySchVO>(prjQuatPrps.getPayList(),prjQuatPrps.getPayList().size());
        prjQuatPrps.setPayListPage(detailListPage);
        BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(detailListPage), CurrentThreadContext.getCurrentUserName());
        return detailListPage;
    }


    /**
     * 报价器测算
     */
    @RequestMapping(value = "/calculate.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object calculate(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        CalQuatPrpsVO prjQuatPrps = null;
        Long id  =	 null;
        try {
            prjQuatPrps = getRequestParams(request);
            //测算
            prjQuatPrps.setSysCd(CurrentThreadContext.getCurrentSysCd());
            prjQuatPrps.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
            prjQuatPrps = this.calQuatPrpsService.calQuatPrpsCalculate(prjQuatPrps);
            ListPageVO<CalPaySchVO> listPage = new ListPageVO<CalPaySchVO>(prjQuatPrps.getPayList(),prjQuatPrps.getPayList().size());
            prjQuatPrps.setPayListPage(listPage);
            result.setData(prjQuatPrps);
            BaseLogUtils.info(logger, "calculate", "测算数据.[id="+id+"] DATA:" + JSONObject.toJSONString(prjQuatPrps), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "calculate", "测算数据失败.DATA:" + JSONObject.toJSONString(prjQuatPrps) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
            ex.printStackTrace();
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "calculate", "测算数据失败.DATA:" + JSONObject.toJSONString(prjQuatPrps) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
            ex.printStackTrace();
        }

        return result;
    }


    private CalQuatPrpsVO getRequestParams(HttpServletRequest request) {
        CalQuatPrpsVO prjQuatPrps = new CalQuatPrpsVO();
        String totLsItmAmt = request.getParameter("totLsItmAmt");//租赁物件总价值（元）
        String contAmt = request.getParameter("contAmt");//合同总额
        String lsPd = request.getParameter("lsPd");//租赁期数
        String lsPdUntCd = request.getParameter("lsPdUntCd");//租赁期数单位
        String annIntRatePct = request.getParameter("annIntRatePct");//租赁年利率
        String payWayCd = request.getParameter("payWayCd");//支付方式
        String actLsAmt = request.getParameter("actLsAmt");//实际融资租赁价值（元）
        String eachEstRntAmt = request.getParameter("eachEstRntAmt");// 每期预估租金（元）
        String lsCalWayCd = request.getParameter("lsCalWayCd");//租赁计算方式（PRJ0012）
        String intRateWayCd = request.getParameter("intRateWayCd");// 租赁年利率计算方式（PRJ0011）
        String detailList = request.getParameter("feeDetailList");//方案费用明细
        String prpsCfgId = request.getParameter("prpsCfgId");
        String prpsCfgNm = request.getParameter("prpsCfgNm");
        String irrPct = request.getParameter("irrPct");//实际收益率
        String isAllowAdd = request.getParameter("isAllowAdd");// 是否允许添加费用项
        String isAllowChg =  request.getParameter("isAllowChg");// 是否可以修改
        String prpsTypCd = request.getParameter("prpsTypCd");//方案类型
        String prdTypCd = request.getParameter("prdTypCd");//产品分类
        String prdIrrPct = request.getParameter("prdIrrPct");//产品分类IRR
        String annIntRatePct2 = request.getParameter("annIntRatePct2");//年利率2
        String speLsPd = request.getParameter("speLsPd");

        //资管模式
        String insQuatTyp = request.getParameter("insQuatTyp");


        //只有当产品类型等于资管产品的时候，才会有机构模式
        if (CalQuatPrpsConstant.CODE_PRPS_PRD_TYP_CD_ZGCP.equals(prpsTypCd)) {
            if(StringUtils.isBlank(insQuatTyp)){
                throw new BaseException("资管机构模式不能为空!");
            } else {
                 prjQuatPrps.setInsQuatTyp(insQuatTyp);
            }

        }



        /*if(StringUtils.isBlank(prdTypCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"产品类型不能为空!");
        }*/

        if(StringUtils.isBlank(prpsTypCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"产品方案政策类型不能为空!");
        }
        if(StringUtils.isNotBlank(prdTypCd)){
            prjQuatPrps.setPrdTypCd(prdTypCd);
        }
        if(StringUtils.isBlank(prdIrrPct)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"产品IRR不能为空!");
        }
        if(Double.valueOf(prdIrrPct)>20||Double.valueOf(prdIrrPct)<4){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请输入合规的产品IRR，范围在4到20之间!");
        }
        prjQuatPrps.setPrdIrrPct(Double.valueOf(prdIrrPct));
        if(StringUtils.isNotBlank(isAllowChg)){
            prjQuatPrps.setIsAllowChg(isAllowChg);
        }
        if(StringUtils.isNotBlank(isAllowAdd)){
            prjQuatPrps.setIsAllowAdd(Integer.valueOf(isAllowAdd));
        }
        if(StringUtils.isNotBlank(irrPct)){
            prjQuatPrps.setIrrPct(Double.valueOf(irrPct));
        }
        if(StringUtils.isNotBlank(prpsTypCd)){
            prjQuatPrps.setPrpsTypCd(prpsTypCd);
        }

        if(StringUtils.isNotBlank(prpsCfgId)){
            prjQuatPrps.setPrpsCfgId(Long.valueOf(prpsCfgId));
        }

        prjQuatPrps.setPrpsCfgNm(prpsCfgNm);
        prjQuatPrps.setDsCd(WebBaseConstant.CHANNEL_CD);
        if(StringUtils.isNotBlank(actLsAmt)){
            prjQuatPrps.setActLsAmt(DecimalUtils.convertYuanToFen(Double.valueOf(actLsAmt)).doubleValue());

        }
        if(StringUtils.isNotBlank(eachEstRntAmt)){
            prjQuatPrps.setEachEstRntAmt(DecimalUtils.convertYuanToFen(Double.valueOf(eachEstRntAmt)).doubleValue());
        }

        if(StringUtils.isEmpty(intRateWayCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁年利率计算方式不能为空!");
        }
        prjQuatPrps.setIntRateWayCd(intRateWayCd);
        if(StringUtils.isEmpty(lsPdUntCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期数单位不能为空!");
        }
        prjQuatPrps.setLsPdUntCd(lsPdUntCd);

        prjQuatPrps.setTotLsItmAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totLsItmAmt)).doubleValue());
        if(StringUtils.isEmpty(contAmt)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"合同总额不能为空!");
        }
        if(!StringUtils.isUnsignedNumeric(contAmt)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"合同总额应为数字!");
        }
        prjQuatPrps.setContAmt(DecimalUtils.convertYuanToFen(Double.valueOf(contAmt)).doubleValue());
        if(StringUtils.isEmpty(lsPd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期数不能为空!");
        }
        if(!StringUtils.isNumeric(lsPd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁期数应为数字!");
        }
        prjQuatPrps.setLsPd(Long.valueOf(lsPd));
        if(StringUtils.isEmpty(payWayCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付方式不能为空!");
        }else{
            if(payWayCd.equals(PrjQuatPrpsConstant.CODE_SING_MONTH_NO_PAY)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"暂不支持该支付方式，请选择其他支付方式!");
            }
        }
        if(PrjQuatPrpsConstant.PAY_WAY_CD_19.equals(payWayCd)
                ||PrjQuatPrpsConstant.PAY_WAY_CD_20.equals(payWayCd)){
            if(!lsPd.equals("24") && !lsPd.equals("36")){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"仅支持24,36期!");
            }
        }
        if(PrjQuatPrpsConstant.PAY_WAY_CD_21.equals(payWayCd)){
            if(!lsPd.equals("12") && !lsPd.equals("18") && !lsPd.equals("24") && !lsPd.equals("36")){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"仅支持12,18,24,36期!");
            }
        }
        if(payWayCd.equals(PrjQuatPrpsConstant.PAY_WAY_CD_19)){
            if(StringUtils.isEmpty(speLsPd)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数不能为空!");
            }
            String[] split = speLsPd.split(",");
            if(split.length != 2){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数格式错误!");
            }
            if(!StringUtils.isNumeric(split[0]) || !StringUtils.isNumeric(split[1])){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数格式错误!");
            }
            if(Long.valueOf(split[0])<7
                    || Long.valueOf(split[0])>(Long.valueOf(lsPd) - 6)
                    || Long.valueOf(split[1])<7
                    || Long.valueOf(split[1])>(Long.valueOf(lsPd) - 6)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数7-" + (Long.valueOf(lsPd) - 6) + "!");
            }
            if(split[0].equals(split[1])){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"不还款期数相同!");
            }
            prjQuatPrps.setSpeLsPd(speLsPd);
        }else{
            prjQuatPrps.setSpeLsPd("");
        }
        prjQuatPrps.setPayWayCd(payWayCd);
        if(!prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_MULTI__STEP_INTER_IRR)/*&&!prjQuatPrps.getPayWayCd().equals(PrjQuatPrpsConstant.CODE_MULTI__STEP_INTER_GH)*/){
            if(StringUtils.isEmpty(annIntRatePct)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁年利率不能为空!");
            }
            if(!StringUtils.isUnsignedNumeric(annIntRatePct)){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁年利率应为数字!");
            }
        }
        prjQuatPrps.setAnnIntRatePct(Double.valueOf(annIntRatePct));
        if(StringUtils.isNotBlank(annIntRatePct2)){
            prjQuatPrps.setAnnIntRatePct2(Double.valueOf(annIntRatePct2));
        }

        if(StringUtils.isEmpty(lsCalWayCd)){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"租赁计算方式不能为空!");
        }
        prjQuatPrps.setLsCalWayCd(lsCalWayCd);
        List<CalQuatPrpsFeeVO> list = new ArrayList<CalQuatPrpsFeeVO>();
        if (StringUtils.isBlank(detailList)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"费用项不能为空!");
        }
        if (StringUtils.isNotBlank(detailList)) {
            list = JSON.parseArray(detailList, CalQuatPrpsFeeVO.class);
        }

        String id = request.getParameter("id");
        double lastAmt = 0d; //尾款，资管业务尾款必填
        boolean fee63 = false;
        for (CalQuatPrpsFeeVO prjQuatPrpsFeeVO : list) {
            if(null==prjQuatPrpsFeeVO.getFeeAmt()){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"费用项金额不能为空!");
            }
            if(null==prjQuatPrpsFeeVO.getIsFixedAmt()){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"是否为固定金额选项不能为空!");
            }
            if(StringUtils.isEmpty(prjQuatPrpsFeeVO.getCntWayCd())){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"费用项计入方式不能为空!");
            }

            if(null==(prjQuatPrpsFeeVO.getFeePct())&&prjQuatPrpsFeeVO.getIsFixedAmt()==BaseConstant.IS_YESNO_NO){
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"固定金额为否，费用比例项不能为空!");
            }
            prjQuatPrpsFeeVO.setFeeAmt(DecimalUtils.convertYuanToFen(prjQuatPrpsFeeVO.getFeeAmt()).doubleValue());//保存到分
            if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_62)){
                lastAmt = prjQuatPrpsFeeVO.getFeeAmt();
            }
            if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_63)){
                Double feeAmt = prjQuatPrpsFeeVO.getFeeAmt();
                if(feeAmt != null && feeAmt>0){
                    fee63 = true;
                }
            }
        }

        if(!fee63){
            throw new BaseException("发票金额必须大于0");
        }
        /*if(prpsTypCd.equals(CalQuatPrpsConstant.CODE_PRPS_PRD_TYP_CD_ZGCP)&&lastAmt==0){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资管业务请选择尾款金额!");
        }*/

        prjQuatPrps.setFeeList(list);
        return prjQuatPrps;
    }


    /**
     * 到厂商列表页面
     */
    @RequestMapping(value = "/toChooseMfrQuatPrpsPage.do", method = { RequestMethod.GET })
    public ModelAndView toChooseMfrQuatPrpsPage(HttpServletRequest request,
                                                HttpServletResponse response) {
        logger.info("加载选择客户列表页面.");
        ModelAndView view = new ModelAndView(
                "project/calQuatPrps/chooseQuatPrpsListPage");
        return view;
    }

    /**
     * 获取机构模式列表，key是模式简称，value是模式的中文
     */
    private void  getInsQuatTypList(ModelAndView view) {

        //所有机构列表
        List<SysDictionaryDTO> allAboutBankInfoList = this.getSysDictionaryList(PrjPlcyIndexConstant.PLCY_VEH_TYP_CD10);

        /*
         * 筛选出符合条件的机构模式
         * codeLvl 等于 1 支持厂商
         * pCode 不是null的
         */
        //[{"key":"pvn_zjd","value":"pvn+尾款"},{"key":"pvn_zjd","value":"pvn+尾款"}]
        com.alibaba.fastjson.JSONArray insQuatTypeJsonArray = new com.alibaba.fastjson.JSONArray();

        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(allAboutBankInfoList)) {
            for (SysDictionaryDTO sysDictionaryDTO:allAboutBankInfoList) {
                if (null != sysDictionaryDTO.getCodeLvl()) {
                    if (BaseConstant.IS_YESNO_YES == sysDictionaryDTO.getCodeLvl() && StringUtils.isNotBlank(sysDictionaryDTO.getPCode())) {

                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("key",sysDictionaryDTO.getPCode());
                        jsonObject.put("value",sysDictionaryDTO.getCodeAttr2());

                        insQuatTypeJsonArray.add(jsonObject);
                    }
                }

            }
        }

        BaseLogUtils.newLogger(String.format("符合条件的机构模式列表：%s", insQuatTypeJsonArray.toJSONString())).info();

        //去重insQuatTypeJsonArray
        String jsonStr = JSONObject.toJSONString(insQuatTypeJsonArray);
        List list = JSONObject.parseArray(jsonStr);
        HashSet hs = new HashSet(list);

        com.alibaba.fastjson.JSONArray filterAfterInsQuatTypeJsonArray = com.alibaba.fastjson.JSONArray.parseArray(hs.toString());

        BaseLogUtils.newLogger(String.format("筛选后的机构模式列表，传给页面的参数：%s", filterAfterInsQuatTypeJsonArray.toJSONString())).info();

        view.addObject("insQuatTypList",filterAfterInsQuatTypeJsonArray);

    }

    /**
     * 不同的资管机构， key是模式简称，value是这个模式的机构中文
     */
    private void differentInsCodeAndInsQuatTyp(ModelAndView view) {
        //所有机构列表
        List<SysDictionaryDTO> allAboutBankInfoList = this.getSysDictionaryList(PrjPlcyIndexConstant.PLCY_VEH_TYP_CD10);
        /**
         * 根据金融机构业务线,设置金融机构名称展示字段值
         */
        //业务线字典List
        List<KeyValueVO> bussinessLineDicList = sysDictionaryApiService.getKvList("REF0048","11000","0000");
        //机构信息List
        List<FriBaseInfoVO> friBaseInfoVOList = this.friBaseInfoService.searchList(new FriBaseInfoQueryCondition());
        //根据金融机构业务线,设置金融机构名称展示字段值
        FundRasInsNmChangeUtil.insNmShowAddBussinessLineDic(friBaseInfoVOList,bussinessLineDicList);
        //修改资管路由机构List中的codeDesc字段值
        if (CollectionUtils.isNotEmpty(friBaseInfoVOList) && CollectionUtils.isNotEmpty(allAboutBankInfoList)) {
            for (SysDictionaryDTO sysDicbankInfoDTO : allAboutBankInfoList) {
                for (FriBaseInfoVO friBaseInfoVO : friBaseInfoVOList) {
                    if (null != friBaseInfoVO.getInsCode()
                            && null!= sysDicbankInfoDTO.getCode()
                            && sysDicbankInfoDTO.getCode().equals(friBaseInfoVO.getInsCode())) {
                        sysDicbankInfoDTO.setCodeDesc(friBaseInfoVO.getFundRasInsNmShow());
                        break;
                    }
                }
            }
        }

        /* 筛选出符合条件的机构模式
         * codeDesc 等于 1 支持厂商
         * pCode 不是null的
         */
        //装模式的jsonArray
        //[{"insQuatTyp":"pvn-1","insCode":"浦发银行"},{"insQuatTyp":"pvn-1","insCode":"民生银行"},{"insQuatTyp":"pvn+尾款","insCode":"中关村银行"},{"insQuatTyp":"pvn+尾款","insCode":"中关村银行"}]
        JSONArray jsonArray = new JSONArray();

        if(org.apache.commons.collections.CollectionUtils.isNotEmpty(allAboutBankInfoList)) {
            for (SysDictionaryDTO sysDictionaryDTO:allAboutBankInfoList) {

                if (null != sysDictionaryDTO.getCodeLvl()) {
                    if (BaseConstant.IS_YESNO_YES == sysDictionaryDTO.getCodeLvl() && StringUtils.isNotBlank(sysDictionaryDTO.getPCode())) {

                        JSONObject jsonObject = new JSONObject();
                        //key是模式的简称
                        jsonObject.put("insQuatTyp",sysDictionaryDTO.getPCode());

                        //value是机构的中文
                        jsonObject.put("insCode",sysDictionaryDTO.getCodeDesc());

                        jsonArray.add(jsonObject);
                    }
                }
            }
        }

        BaseLogUtils.newLogger(String.format("查询不同的机构的模式，传给页面的参数：%s", jsonArray)).info();
        view.addObject("diffInsCodeAndinsQuatTyp",jsonArray);

    }
    /**
     * 得到中文全称的银行
     * @param view
     */
    private void getInsCodeList(ModelAndView view) {
        List<SysDictionaryDTO> allAboutBankInfoList = this.getSysDictionaryList(PrjPlcyIndexConstant.PLCY_VEH_TYP_CD10);

        /*
         * 筛选出符合条件的机构
         * CodeLvl 等于 1 支持厂商
         * pCode 模式不是null的
         */
        List<String> bankCodeList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(allAboutBankInfoList)) {
            for (SysDictionaryDTO sysDictionaryDTO:allAboutBankInfoList) {
                if (null != sysDictionaryDTO.getCodeLvl()) {

                    if (BaseConstant.IS_YESNO_YES == sysDictionaryDTO.getCodeLvl() && StringUtils.isNotBlank(sysDictionaryDTO.getPCode())) {
                        bankCodeList.add(sysDictionaryDTO.getCode());
                    }
                }

            }
        }

        //机构集合
        //再去找符合条件的机构的中文,绑定到视图上
        FriBaseInfoQueryCondition condition = new FriBaseInfoQueryCondition();
        condition.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
        condition.setInsUseCd("2");   //2 是机构用途:如资管，融资
//        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
//        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        //这得出来的是所有的银行，需要跟上面的集合过滤下
        List<FriBaseInfoVO> allBankChineseCodeList = this.friBaseInfoService.searchList(condition);

        //装中文银行的集合
        List<FriBaseInfoVO> bankChineseCodeList = new ArrayList<>();

        if (CollectionUtils.isNotEmpty(allBankChineseCodeList)) {
            for (String bankCode:bankCodeList) {
                for (FriBaseInfoVO friBaseInfoVO:allBankChineseCodeList) {
                    if (friBaseInfoVO.getInsAbb().toLowerCase().contains(bankCode)) {
                        bankChineseCodeList.add(friBaseInfoVO);
                    }
                }
            }
        }

        //银行的集合
        view.addObject("bankChineseCodeList",bankChineseCodeList);

    }
    /**
     * 数据字典
     * @return
     */
    private List<SysDictionaryDTO> getSysDictionaryList(String codeGrpCd) {
        return this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),codeGrpCd);
    }
}

